home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 289_01.zip / BDTTY.C < prev    next >
Text File  |  1993-04-26  |  6KB  |  197 lines

  1. /*-----------------------------------------------------------------------------
  2. BDTTY.C
  3.  
  4. This file contains the board display routines for TTY type terminals.
  5.  
  6.  
  7. Revision History
  8. ----------------
  9. Jon Ward    24 Nov 1988    Initial Revision
  10. Jon Ward    10 Dec 1988    Added more functions for displaying game info.
  11. Jon Ward     7 Jan 1989    Added player_moved_to function. Consolidated
  12.                   functions that separately handled us/them.
  13. -----------------------------------------------------------------------------*/
  14.  
  15. #include <conio.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18.  
  19. #include "othello.h"
  20.  
  21.  
  22. /*-----------------------------------------------------------------------------
  23.              Global Varaible Declarations
  24. -----------------------------------------------------------------------------*/
  25. char us_char = 'X';    /* character to put on the board when WE move */
  26. char them_char = 'O';    /* Character to put on the board when THEY move */
  27.  
  28.  
  29. /*-----------------------------------------------------------------------------
  30.                         Local Variable Declarations
  31. -----------------------------------------------------------------------------*/
  32. char bd_top [] = "     1   2   3   4   5   6   7   8  ";
  33.  
  34. #if 0        /*** use non-zero for REAL TTY output ***/
  35. char bd_div [] = "   |---+---+---+---+---+---+---+---|";
  36. char bd_row [] = "   |   |   |   |   |   |   |   |   |";
  37.  
  38. #else        /*** else, output as IBM PC characters ***/
  39. char bd_div [] = "   \xC5\xC4\xC4\xC4\xC5\xC4\xC4\xC4\xC5\
  40. \xC4\xC4\xC4\xC5\xC4\xC4\xC4\xC5\xC4\xC4\xC4\xC5\
  41. \xC4\xC4\xC4\xC5\xC4\xC4\xC4\xC5\xC4\xC4\xC4\xC5";
  42.  
  43. char bd_row [] = "   \xB3   \xB3   \xB3   \xB3   \xB3   \
  44. \xB3   \xB3   \xB3   \xB3";
  45. #endif
  46.  
  47.  
  48. /*-----------------------------------------------------------------------------
  49.                          Local Constant Definitions
  50. -----------------------------------------------------------------------------*/
  51. #define BD_LET 1    /* position in bd_row where the letter goes */
  52. #define BD_OFS 5    /* position in bd_row where pieces start */
  53. #define BD_LEN 4    /* distance between pieces on board */
  54.  
  55.  
  56. /*-----------------------------------------------------------------------------
  57. void disp_board (board_type *board)
  58.  
  59. This function will display the "us" and "them" pieces for the board pointed
  60. to by the board argument.
  61. -----------------------------------------------------------------------------*/
  62.  
  63. void disp_board (board_type *board)    /* pointer to board to display */
  64. {
  65. register int r;
  66. register int c;
  67. char buf [81];
  68.  
  69. memset (buf, '-', sizeof (buf) - 1);    /* gen a line of dashes */
  70. buf [sizeof (buf) - 1] = '\0';        /* terminate it with a NULL */
  71.  
  72. printf ("\n%s\n\n%s\n%s\n", buf, bd_top, bd_div);
  73.  
  74. for (r = 1; r <= 8; r++)
  75.   {
  76.   bd_row [BD_LET] = (char) (r + 'A' - 1);
  77.   for (c = 1; c <= 8; c++)
  78.     {
  79.     char piece;
  80.  
  81.     switch (board->board [r][c] & (US_PIECE | THEM_PIECE))
  82.       {
  83.       case US_PIECE:
  84.     piece = us_char;
  85.     break;
  86.  
  87.       case THEM_PIECE:
  88.     piece = them_char;
  89.     break;
  90.  
  91.       default:
  92.     piece = ' ';
  93.     break;
  94.       }
  95.  
  96.     bd_row [BD_OFS + (c-1) * BD_LEN] = piece;
  97.     }                        /* END for (c = 1... */
  98.  
  99.   printf ("%s\n%s\n", bd_row, bd_div);
  100.   }                        /* END for (r = 1... */
  101.  
  102. printf ("\n");
  103. }
  104.  
  105.  
  106. /*-----------------------------------------------------------------------------
  107. -----------------------------------------------------------------------------*/
  108.  
  109. void disp_row (int row)
  110. {
  111. printf ("%c", 'A' + row);
  112. }
  113.  
  114.  
  115. /*-----------------------------------------------------------------------------
  116. -----------------------------------------------------------------------------*/
  117.  
  118. void disp_col (int col)
  119. {
  120. printf ("%c", '1' + col);
  121. }
  122.  
  123.  
  124. /*-----------------------------------------------------------------------------
  125. -----------------------------------------------------------------------------*/
  126.  
  127. void disp_clr_row_col ()
  128. {
  129. printf ("\r  \r");
  130. }
  131.  
  132.  
  133. /*-----------------------------------------------------------------------------
  134. -----------------------------------------------------------------------------*/
  135.  
  136. void disp_init ()
  137. {
  138. printf ("\n\n\n");
  139. }
  140.  
  141.  
  142. /*-----------------------------------------------------------------------------
  143. -----------------------------------------------------------------------------*/
  144.  
  145. void disp_error_msg (char *msg)
  146. {
  147. printf ("\n\aError: %s\nPress any key to continue\n", msg);
  148. getch ();
  149. }
  150.  
  151.  
  152. /*-----------------------------------------------------------------------------
  153. -----------------------------------------------------------------------------*/
  154.  
  155. void disp_player_move (unsigned char player)
  156. {
  157. printf ((player & US_PIECE) ? "\nOne Moment While I Move...\n" :
  158.     "\nEnter Your Move\a\n");
  159. }
  160.  
  161.  
  162. /*-----------------------------------------------------------------------------
  163. -----------------------------------------------------------------------------*/
  164.  
  165. void disp_player_cant_move (unsigned char player)
  166. {
  167. printf ("\n%s Can't Move\n", (player & US_PIECE) ? "I" : "You");
  168. printf ("Press any key to continue\n");
  169. getch ();
  170. }
  171.  
  172. /*-----------------------------------------------------------------------------
  173. -----------------------------------------------------------------------------*/
  174.  
  175. void disp_player_moved_to (unsigned char player)
  176. {
  177. printf ("%s Moved To: ", (player & US_PIECE) ? "I" : "You");
  178. }
  179.  
  180. /*-----------------------------------------------------------------------------
  181. -----------------------------------------------------------------------------*/
  182. void disp_pieces (int us, int them)
  183. {
  184. printf ("\nI have %d pieces.  You have %d pieces.\n", us, them);
  185.  
  186. if (us < them)
  187.   printf ("You won.  Play again -- you won't be so lucky next time.\n");
  188. else if (us > them)
  189.   printf ("I won. -- Read 'em and weep!\n");
  190. else
  191.   printf ("The game was a tie.\n");
  192. }
  193.  
  194. /*-----------------------------------------------------------------------------
  195. -----------------------------------------------------------------------------*/
  196.  
  197.